package ganga.custodian.settings;

import ganga.custodian.R;
import ganga.custodian.ui.Builder;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class SelectCardioMonitor extends Activity {

	// Return Intent extra
    public static String CARDIO_MONITOR_NAME = "CardioMonitorName";

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.selectcardiomonitor);

		// Set result CANCELED in case the user backs out
        setResult(Activity.RESULT_CANCELED);
		
        buildListView(R.id.AvaibleCardioMonitors, R.array.CardioMonitors);
		//builder.buildSpinner(R.id.SelectCardioMonitorSpinner, R.array.CardioMonitors);
	}
	@Override
	protected void onResume() {
		super.onResume();
	}
	Builder builder = new Builder(this);
	private void buildListView(int id, int stringArrayId){
		 ListView listView = (ListView) findViewById(id);
		 ArrayAdapter<CharSequence> anAdapter = ArrayAdapter.createFromResource(
					this, stringArrayId, R.layout.simple_listview_item);
		 listView.setAdapter(anAdapter);
		 listView.setOnItemClickListener(itemClickListener);
	}
	// The on-click listener for all devices in the ListViews
    private OnItemClickListener itemClickListener = new OnItemClickListener(){
    	public void onItemClick(AdapterView<?> av, View v, int arg2, long arg3){
    		String selected = ((TextView) v).getText().toString();
    		
            // Create the result Intent and include the MAC address
            Intent intent = new Intent();
            intent.putExtra(CARDIO_MONITOR_NAME, selected);

            // Set result and finish this Activity
            setResult(Activity.RESULT_OK, intent);
            finish();
    	}
    };//item click
}
